﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>UpdatePwd</title>
    <script src="../../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $.ajaxSetup({ cache: false });
        })

        function CheckPwd() {
            if ($("#newpassword").val() == "" && $("#againpassword").val() == "" && $("#oldpassword").val() == "") {
                alert("请确认后再操作！");
                return false;
            }
            if ($("#againpassword").val() == "") {
                alert("重新输入的新密码不能为空！");
                return false;
            }
            if ($("#newpassword").val() == "") {
                alert("新密码不能为空！");
                return false;
            }
            if ($("#newpassword").val() != $("#againpassword").val()) {
                alert("两次输入的密码不相同！");
                return false;
            }
            $.ajax({
                type: "POST",
                url: "/Account/UpdatePwd",
                data: { newpassword: function () { return $("#newpassword").val() } },
                success: function () {
                    alert("修改成功！");
                    window.parent.location = "/Account/Login";
                }
            });
        }

        function CheckOwner(ctr) {
            var value = $(ctr).val();
            $.ajax({
                type: "GET",
                url: "/Account/IsOwner",
                data: { oldPassword: value },
                success: function (msg) {
                    if (msg != "success") {
                        alert("与原密码不符！");
                        $(ctr).focus();
                    }
                }
            });
        }

    </script>
</head>
<body>
 <form id="passwordForm" method="post">
    <div>
        <table>
            <tr>
                <td>
                    旧&nbsp;&nbsp;密&nbsp;&nbsp;码：
                </td>
                <td>
                    <input id="oldpassword" name="oldpassword" type="text" onblur="CheckOwner(this)" />
                </td>
            </tr>
            <tr>
                <td>
                    新&nbsp;&nbsp;密&nbsp;&nbsp;码：
                </td>
                <td>
                    <input id="newpassword" name="newpassword" type="text"/>
                </td>
            </tr>
            <tr>
                <td>
                    再次输入新密码：
                </td>
                <td>
                    <input id="againpassword" name="againpassword" type="text"/>
                </td>
            </tr>
            <tr>
                <td>
                    <input id="bun" name="bun" type="button" value="提交" onclick="CheckPwd()" />
                </td>
            </tr>
        </table>  
    </div>
    </form>
</body>
</html>
